package com.redoor.app.stake.auth.controller;

import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import com.redoor.app.stake.auth.model.BaseUserOrg;
import com.redoor.app.stake.auth.model.BaseUserOrgCriteria;
import com.redoor.app.stake.auth.service.BaseUserOrgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-02-07 15:19:13.
*/
@RestController
@RequestMapping("/base/user/orgs")
public class BaseUserOrgController {

    @Autowired
    private BaseUserOrgService baseUserOrgService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseUserOrg baseUserOrg) {
        baseUserOrgService.save(baseUserOrg);
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable String id) {
        baseUserOrgService.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody BaseUserOrg baseUserOrg) {
        baseUserOrgService.updateBySelective(baseUserOrg);
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping("/{id}")
    public ResponseResult detail(@PathVariable String id) {
        BaseUserOrg baseUserOrg = baseUserOrgService.findById(id);
        return ResultGenerator.generatorSuccess(baseUserOrg);
    }

    @GetMapping
    public ResponseResult list(BaseUserOrgCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<BaseUserOrg> list = baseUserOrgService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

}
